﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace MINERP.DAL.CustomerManage
{
    public class DisposePhotoDAL
    {
        //参数
        private SqlConnection con;
        //private string conStr = ConfigurationManager.ConnectionStrings["fffff"].ToString();
        private string conStr = DALBase.ConnStr;
        #region 员工的理件路径
        /// <summary>
        /// 员工的理件路径
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string GetUserDisposePhotoPath(int userId)
        {
            try
            {
                using (con = new SqlConnection(conStr))
                { 
                    string sql = "select DisposePhotoPath from users where userid=" + userId;
                    SqlCommand cmd = new SqlCommand(sql, con);
                    con.Open();
                    object obj = cmd.ExecuteScalar();
                    if (obj == null)
                    {
                        return "";
                    }
                    else
                    {
                        return obj.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取所有可用的商户
        /// <summary>
        /// 获取所有可用的商户
        /// </summary>
        /// <returns></returns>
        public DataTable GetShops()
        {
            try
            {
                using (con = new SqlConnection(conStr))
                {
                    string sql = "select ShopId,ShopName,mnemonicCode as ZJCode from shop where status=1 order by shopName";
                    SqlCommand cmd = new SqlCommand(sql, con);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    con.Open();
                    adapter.Fill(dt);
                    return dt;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 获取所有有效的员工
        /// <summary>
        /// 获取所有有效的员工
        /// </summary>
        /// <returns></returns>
        public DataTable GetUsers()
        {
            try
            {
                using (con = new SqlConnection(conStr))
                {
                    string sql = "select UserId,UserName from users where isuseful=1 order by username";
                    SqlCommand cmd = new SqlCommand(sql, con);
                    SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
                    DataTable dt = new DataTable();
                    con.Open();
                    adapter.Fill(dt);
                    return dt;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 修改员工的理件路径
        /// <summary>
        /// 修改员工的理件路径
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="path"></param>
        public void UpdateUserDisposePath(int userId, string path)
        {
            try
            {
                using (con = new SqlConnection(conStr))
                {
                    string sql = "update users set DisposePhotoPath='" + path + "' where userid=" + userId;
                    SqlCommand cmd = new SqlCommand(sql, con);
                    con.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        public DataTable GetUsers(int inUserID)
        {
            try
            {
                using (con = new SqlConnection(conStr))
                {
                    string sql = "select UserId,UserName,DisposePhotoPath from users where userID=" + inUserID + "and  isuseful=1";
                    SqlCommand cmd = new SqlCommand(sql, con);
                    SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
                    DataTable dt = new DataTable();
                    con.Open();
                    adapter.Fill(dt);
                    return dt;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
